import * as qiniu from 'qiniu-js';

export const imgUploads = (token, domain, file) => {
    return new Promise((resolve, reject) => {
        let key = Date.parse(new Date()) + ".png";
        let config = {
            region: qiniu.region.z2,
            uptoken: token,
            domain: domain,     //配置好的七牛云域名  如   https://cdn.qniyun.com/
            unique_names: false,
        };
        let putExtra = {
            fname: "",
            params: {},
            mimeType: [] || null
        };
        let observable = qiniu.upload(file, key, token, putExtra, config)
        let subscription = observable.subscribe({
            next(res) {
                if (res.total.percent === 100) {
                    resolve(key)
                }
            },  // 接收上传进度信息的回调函数
            error(err) {
                reject('上传失败');
            },  //上传错误后触发
            complete(res) {
            }  //停止当前文件上传
        }) // 上传开始
    })
}

